//获取应用实例
var app = getApp()
var util = require('../../utils/util.js');
var commonService = require('../../services/commonService.js');
var userGroupService = require('../../services/userGroupService.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    hasMore:true,
    pageIndex:1,
    pageSize:10,
    groups:[]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    that.myGroupList();
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  },
  myGroupList: function (append){
    var that = this;
    //是否继续加载，activityHasMore=false说明上一次查询之后没有获得更多数据了，因此不要再向服务器请求新的数据
    if (this.data.hasMore) {
      userGroupService.myGroupList({
        user_id: app.globalData.sysUserInfo.userId,
        pageIndex: that.data.pageIndex,
        pageSize: that.data.pageSize,
        success: function (resultData){
         
          var groups = [];
          if (append == 1) {
            groups = that.data.groups;
          }
          for (var i = 0; i < resultData.list.length; i++) {
            groups.push(resultData.list[i]);
          }
          console.log(groups);
          that.setData({
            groups: groups,
            hasMore: resultData.hasMore
          });
        }
      });
    }
  },
  groupDetail:function(e){
    var id = e.currentTarget.dataset.id;
    wx.navigateTo({
      url: '../myteam/myteam?group_id='+id,
    })
  },
  releaseMyGroupList:function(){
    this.myGroupList(1);
  },
  backTopPrevNavigate: function () {
    wx.navigateBack()
  },
})